   package com.javalong.affairs.module.userModule.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.javalong.affairs.R;
import com.javalong.affairs.base.adapter.BaseAdapter;
import com.javalong.affairs.base.constant.StatusCode;
import com.javalong.affairs.base.model.UserStatistic;

public class UserStatisticAdapter extends BaseAdapter {
	public UserStatisticAdapter(Context context, List<?> dataList) {
		super(context, dataList);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final UserStatistic user = (UserStatistic) getItem(position);
		ViewHolder holder;
		if (convertView != null) {
			holder = (ViewHolder) convertView.getTag();
		} else {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.item_user_statistic, null);
			holder.tv_user = (TextView) convertView.findViewById(R.id.tv_user);
			holder.tv_status = (TextView) convertView
					.findViewById(R.id.tv_status);
			holder.ll_reason = (LinearLayout) convertView
					.findViewById(R.id.ll_reason);
			holder.tv_reason = (TextView) convertView
					.findViewById(R.id.tv_reason);
			convertView.setTag(holder);
		}
		holder.tv_user.setText(user.rootName);
		if (user.receiveStatus == 7) {
			holder.tv_status.setText(StatusCode
					.getStatisticStatus(user.receiveStatus)
					+ "("
					+ user.receiveName + ")");
		} else {
			holder.tv_status.setText(StatusCode
					.getStatisticStatus(user.receiveStatus));
		}

		if (user.receiveStatus == -1 || user.receiveStatus == 0
				|| user.receiveStatus == 1) {
			holder.ll_reason.setVisibility(View.GONE);
		} else {
			holder.ll_reason.setVisibility(View.VISIBLE);
			if (user.receiveStatus == 2) {
				holder.tv_reason.setText(user.receiveReason);
			} else {
				holder.tv_reason.setText(user.sendReason);
			}
		}
		return convertView;
	}

	class ViewHolder {
		TextView tv_user;
		TextView tv_status;
		LinearLayout ll_reason;
		TextView tv_reason;

	}

}
